<script lang="jsx" setup>
import dayjs from 'dayjs';
import { computed, nextTick, ref } from 'vue';

const commonSearchRef = ref(null);
const tableRef = ref(null);
const searchParams = ref({
  lotId: null,
  moduleNo: null,
  time: null
});

const searchFormList = [
  {
    type: 'input',
    key: 'lotId',
    label: '批卡号',
    placeholder: '请输入批卡号',
    span: 24,
    md: 12,
    lg: 8,
    xl: 8,
    xxl: 6
  },
  {
    type: 'input',
    key: 'moduleNo',
    label: '生产型号',
    placeholder: '请输入生产型号',
    span: 24,
    md: 12,
    lg: 8,
    xl: 8,
    xxl: 6
  },
  {
    type: 'dateRangePicker',
    key: 'time',
    label: '日期',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    showTime: true
  }
];

const searchData = computed(() => {
  const params = {
    ...searchParams.value
  };
  if (searchParams.value?.time?.[0]) {
    params.startTime = dayjs(searchParams.value.time[0]).format('YYYY-MM-DD');
    params.endTime = dayjs(searchParams.value.time[1]).format('YYYY-MM-DD');
  }
  delete params.time;
  return params;
});

const column = [
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 70,
    fixed: 'left',
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'moduleNo',
    dataIndex: 'moduleNo',
    title: '生产型号',
    align: 'center',
    fixed: 'left',
    checked: true,
    ellipsis: true
  },
  {
    key: 'lotId',
    dataIndex: 'lotId',
    title: '批卡号',
    align: 'center',
    fixed: 'left',
    checked: true,
    ellipsis: true
  },

  {
    key: 'recipeName',
    dataIndex: 'recipeName',
    title: '配方',
    align: 'center',
    width: 370,
    checked: true,
    ellipsis: true
  },

  {
    key: 'sendResult',
    dataIndex: 'sendResult',
    title: '下发结果',
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '创建时间',
    align: 'center',
    checked: true,
    ellipsis: true,
    customRender: ({ record }) => {
      return dayjs(record.createDate).format('YYYY-MM-DD HH:mm:ss');
    }
  },
  {
    key: 'operator',
    dataIndex: 'operator',
    title: '操作人',
    width: 100,
    align: 'center',
    checked: true,
    ellipsis: true
  }
];

function search() {
  tableRef.value.getData(1);
}

function reset() {
  nextTick(() => {
    searchParams.value = {
      lotId: null,
      moduleNo: null,
      time: null
    };
    search();
  });
}
</script>

<template>
  <div
    class="code-whitelist-page jl-main-page min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto"
  >
    <CommonSearch
      ref="commonSearchRef"
      v-model:searchParams="searchParams"
      :form-list="searchFormList"
      :is-search="true"
      @search="search"
      @reset="reset"
    ></CommonSearch>

    <Table
      ref="tableRef"
      v-model:searchParams="searchData"
      :column="column"
      :show-row-selection="false"
      :auto-generate-uuid="true"
      :scroll="{ y: 'auto' }"
      is-init-get-data
      url="/mes/pressRelease/pageList"
    ></Table>
  </div>
</template>

<style lang="scss" scoped></style>
